package edu.zcmu.seckill.vo;


import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import edu.zcmu.seckill.entity.Order;
import edu.zcmu.seckill.entity.Product;
import edu.zcmu.seckill.entity.SeckillProduct;
import edu.zcmu.seckill.rocket.consumer.OrderConsumer;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class ProductOrderVo {

    private String orderId;
    private BigDecimal price;
    private String pDescribe;
    private String name;
    private String img;
    private String createTime;


    public static ProductOrderVo createProductOrderVo(Order order, Product product){
        ProductOrderVo productOrderVo = new ProductOrderVo();

        productOrderVo.setOrderId(order.getId());

        productOrderVo.setPrice(order.getTotalPrice());

        productOrderVo.setName(order.getProductName());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(order.getCreateTime());
        productOrderVo.setCreateTime(dateString);
        productOrderVo.setImg(product.getImg());

        return productOrderVo;
    }
}
